// import { defineStore } from "pinia";
import axios from "axios";
// import { ElMessage } from "element-plus";

// import { getCurrentInstance } from "vue";
// const instance = getCurrentInstance();
const AUTH_BASE_URL = "http://119.91.102.80:801/api";

const AuthAPI2 = {
  async login(data) {
    try {
      const rsaRes = await axios.get(`${AUTH_BASE_URL}/auth/rsa?type=1&pass=` + data.password);
      const loginRes = await axios.get(
        `${AUTH_BASE_URL}/auth/login?userName=${data.username}&password=${rsaRes.data.replace(/\+/g, "%2B")}`
      );
      return loginRes.data;
      // if (loginRes.data.Success) {
      //   this.token = loginRes.data.Data;
      //   localStorage.setItem("token", this.token);
      //   return true;
      // } else {
      //   this.error = loginRes.data.Msg;
      //   this.$message({
      //     type: "error",
      //     message: loginRes.data.Msg,
      //   });
      //   ElMessage.error(loginRes.data.Msg);
      //   return false;
      // }

      // this.error = loginRes.data.Msg
      // return false
    } catch (err) {
      console.log(err);
      // ElMessage.error("登录失败，请重试");
      // this.error = "登录失败，请重试";
      return false;
    }
  },
  setIsAuthenticated(value) {
    this.isAuthenticated = value;
    localStorage.setItem("isAuthenticated", value.toString());
  },
  logout() {
    this.isAuthenticated = false;
    localStorage.removeItem("isAuthenticated");
  },
};

export default AuthAPI2;
